<html>
<head>
	<script>

window.addEvent('domready', function() {
   
   	for(i=0;i<24;i++)
	{
	var obj ='dtask'+(i+1).toString();
		$(obj).setStyles({width:'80px',height:'55px','background-color': '#E0ECFF',margin: '2px 1px 2px 2px'});		
	}
});


		$j(function(){
			$j('.drag').draggable({
				proxy:'clone',
				revert:true,
				cursor:'auto',
				onStartDrag:function(){

				},
				onStopDrag:function(){

				}
			});
			$j('#taskpdts').droppable({
				onDragEnter:function(e,source){
					$j(source).draggable('proxy').css('border','1px solid red');
				},
				onDragLeave:function(e,source){
					$j(source).draggable('options').cursor='not-allowed';
				},
				onDrop:function(e,source){
					//$j(this).append(source);
					var prjidd = $('id_gezi_prj').innerHTML;
					var gpp = $('geziPerPage').innerHTML;
					var pn = $('pageNum').innerHTML;
					var taskidd = $('d'+'id_gezi_task').innerHTML;
					var tngezi = $('d'+'nowGezi').innerHTML;
					var tpn = $('d'+'TpageNum').innerHTML;
					//alert(gpp+':'+tngezi);
					
					if($chk(gpp) && $chk(tngezi) && (parseInt(gpp)<=(24-parseInt(tngezi))) && $chk(pn) && $chk(tpn) && (parseInt(pn)==parseInt(tpn)) )
					{
					//alert('ok');		
					confirmme(prjidd,taskidd,source);
					
					}
					else
					{
					var tgg = 24-parseInt(tngezi);
					msg("<span style='color:red;'>不匹配</span>",'肯剩余格子空位不够:'+gpp+'大于'+tgg+'<br />或张数不匹配:'+pn+'不等于'+tpn);
					}
				
				}
			});
		});
		
		function confirmme(prjidd,taskidd,source){
			$j.messager.confirm('确认项目'+prjidd+'加入任务'+taskidd+'？', '加入后不可更改，请确定任务中没有直接竞争性商品', function(r){
				if (r){
					//alert('join ok'+r);
					$j('#taskpdts').append(source);
					operdata();//完成ajax操作后台数据，显示成功或者失败
					
				}
			});
		}	
	
	//拖拽后处理函数	
	function operdata()
		{
		var prjidd = $('id_gezi_prj').innerHTML;
		var gpp = $('geziPerPage').innerHTML;
		var pn = $('pageNum').innerHTML;
		var taskidd = $('d'+'id_gezi_task').innerHTML;
		var tngezi = $('d'+'nowGezi').innerHTML;
		var nowLoc = $('d'+'nowLoc').innerHTML;		
		var tpn = $('d'+'TpageNum').innerHTML;
		
		//1.taskprj表添加记录 2.prj表更改状态  3.判断task是否满格，满了则更改task状态
		var callback = function (data){
				if(data[0]['status']='ok')
				{
					if($chk(data[0]['data'])) 
					{
					addPrjpdt2Task(prjidd,taskidd);
					msg('恭喜你！','项目加入任务成功！');
					}
				}
				else
				{
				msg('更新数据失败','请重新尝试匹配');
				}
		};
		var datastr = 'id_gezi_prj='+prjidd+'&geziPerPage='+gpp+'&id_gezi_task='+taskidd+'&nowGezi='+tngezi+'&pageNum='+pn+'&nowLoc='+nowLoc;
		var urlstr = '__APP__/Util/joinTask';
		ajaxGet(urlstr,datastr,callback);		
		}	
//项目加入任务成功后回调函数，把项目产品信息html加入到当前显示任务中		
	function addPrjpdt2Task(prjidd,taskidd)
	{	//alert('22');
		var couponTab0 = $('nowGezi'+taskidd).value;
		var pdtcount = $('geziPerPage'+prjidd).innerHTML;
		var tpdtIndex;
		for(i=1;i<=pdtcount;i++)
		{
		tpdtIndex = couponTab0+i;
		$('dtask'+tpdtIndex).innerHTML = 'sdfsdf';
		}
	
	}				
 function showprj(index)
 {
	 if(index!='项目ID')
	 {	 	$('pageNum').innerHTML=$('pageNum'+index).value;
		$('geziPerPage').innerHTML=$('geziPerPage'+index).value;
		$('geziNum').innerHTML=$('geziNum'+index).value;
		$('ctime').innerHTML=$('ctime'+index).value;
		$('owner').innerHTML=$('owner'+index).value;
		$('type').innerHTML=$('type'+index).value;
		$('id_gezi_prj').innerHTML=$('id_gezi_prj'+index).value;
		showpdts(index);	 
	 }
 }	
  function showtask(kind,index)  
 {	
 	var prjidd = $('id_gezi_prj').innerHTML.length;
	var prjpagenum = parseInt($('pageNum').innerHTML);
	cleartaskdiv();	
	var taskpage = parseInt($('TpageNum'+index).value);
	
	 if(   (prjidd>0)  )
	 {	
	 	if(prjpagenum==taskpage)
	 	{
	 		add2Tab(kind,index);
			showtaskd(index,kind);
		}
		else
		{
		msg('提醒:<span style="color:red;">张数不等</span>:'+$('pageNum').innerHTML+':'+$('TpageNum'+index).value,'请重新选择匹配项目<br/>或创建当前任务子项目');
		add2Tab(kind,index);
		showtaskd(index,kind);
		}
	 }
	else
	{
		//msg('提醒：你没有选择项目','如果没有可执行项目，可以创建当前任务子项目');
		add2Tab(kind,index);
		showtaskd(index,kind);
	}
 }
 //把任务列表内容填充到表格的执行函数
 function add2Tab(kind,index)
 {
	if(kind=='dtask') 
	{
		$('d'+'task_ctime').innerHTML=$('task_ctime'+index).value;
		$('d'+'TpageNum').innerHTML=$('TpageNum'+index).value;
		$('d'+'percent').innerHTML=$('percent'+index).value;
		$('d'+'status').innerHTML=$('status'+index).value;
		$('d'+'task_type').innerHTML=$('task_type'+index).value;
		$('d'+'tTgezi').innerHTML=$('tTgezi'+index).value;
		$('d'+'nowGezi').innerHTML=$('nowGezi'+index).value;
		$('d'+'nowLoc').innerHTML=$('nowLoc'+index).value;		
		$('d'+'score').innerHTML=$('score'+index).value;						
		$('d'+'id_gezi_task').innerHTML=$('id_gezi_task'+index).value;
	}
	else
	if(kind=='ftask')
	{
		$('f'+'task_ctime').innerHTML=$('task_ctime'+index).value;
		$('f'+'TpageNum').innerHTML=$('TpageNum'+index).value;
		$('f'+'percent').innerHTML=$('percent'+index).value;
		$('f'+'status').innerHTML=$('status'+index).value;
		$('f'+'task_type').innerHTML=$('task_type'+index).value;
		$('f'+'tTgezi').innerHTML=$('tTgezi'+index).value;
		$('f'+'nowGezi').innerHTML=$('nowGezi'+index).value;
		$('f'+'nowLoc').innerHTML=$('nowLoc'+index).value;				
		$('f'+'score').innerHTML=$('score'+index).value;						
		$('f'+'id_gezi_task').innerHTML=$('id_gezi_task'+index).value;
	}
 }
  function showpdts(prjid)
  {
  $('pdts').innerHTML ='';  		
	var callback = function(data){
		if(data[0]['status']='ok')
		{
		if($chk(data[0]['data'])) 
		{
		//msg('提醒','显示项目详细信息');
		var recs = data[0]['data']['a'];
		//alert(recs.length);
		//获得项目对应的多个产品，显示图片和淘宝价格
		var htmlstr = "<table><tr>";
			for(i=0;i<recs.length;i++)
			{
			var tCode = recs[i]['tCode'];
			var pPic = recs[i]['pPic'];
			var pName = recs[i]['pName'].substring(0,15);			
		
			var pTprice = recs[i]['pTprice'];			
			var productUrl = recs[i]['productUrl'];
			var prj_pic = recs[i]['prj_pic'];
			br =((i+1)%4)==0?'</tr>':'';
			//alert(i+br);			
			 htmlstr = htmlstr +"<td><a href='"+productUrl+"' target='_blank' border=0 >"+"<img src='"+	pPic+"' alt='"+'优惠码：'+tCode+"' width=80 height=80 /> </a>"+
			"<div style='word-wrap:break-word;width:90px;'>"+pName+"</div> ; 价格："+pTprice+'</td>'+br;			
			}
			htmlstr = htmlstr +'</table>';
			$j('#pdts').append(htmlstr);
			$j('#pdts').focus();
			//alert(htmlstr);	
		}
		else msg('错误!'+data[0]['msg']);
		}
		};
	var datastr = 'id_gezi_prj='+prjid+'&status='+'beginExec';
	var urlstr = '__APP__/Util/getPrjdtinfo';
	ajaxGet(urlstr,datastr,callback);
  }
  
  function showtaskd(taskid,kind)
  {
  if(kind=='dtask')
  {var status='Adding';}
  else
  if(kind=='ftask')
  {var status='Full';}
 
	var callback = function(data)
     {
		if(data[0]['status']='ok')
		{
			if($chk(data[0]['data'])) 
			{
			//msg('提醒','显示任务详细信息');
			var recs = data[0]['data'];
			for(i=1;i<=recs.length;i++)
				{
				$(kind+i.toString()).innerHTML = "<a href='"+recs[i-1]['productUrl'] + "' target='_blank'> <img src='"+recs[i-1]['pPic']+"' border=0 width=79 height=54 title='"+recs[i-1]['tCode']+"' /> </a>";
				}
			for(j=i;j<=24;j++)	//只有未满格任务才这行这里
				{
				var tp =$('d'+'TpageNum').innerHTML;
				//var htmmlstr =  "<input type='button' style='width=78;height=53' value='快捷加入' onclick='djointask("+(i-1)+','+taskid+','+tp+");' />";
				var htmmlstr = "空位";
				//alert(htmmlstr);
				$('dtask'+j.toString()).innerHTML =htmmlstr;
				}
			}
			else msg('错误!'+data[0]['msg']);
		}
	  }
	var datastr = 'id_gezi_task='+taskid+'&status='+status;
	var urlstr = '__APP__/Util/getTaskprjpdtinfo';
	ajaxGet(urlstr,datastr,callback);
  }
  
  function cleartaskdiv()
  {
	for(i=1;i<=24;i++)
		{
		var tp1 = $('ftask'+i.toString());
		var tp2 = $('dtask'+i.toString());
		if($chk(tp1))
		{tp1.innerHTML = '';}
		if($chk(tp2))
		{tp2.innerHTML = '';}		
		}
  }


	function popwin(urlstr,datastr)
	{
	$j('#pop').panel();

	$j('#pop').load(urlstr+datastr);
	$j('#winpop').window('open');
	//
	}			 
	</script>
</head>
<body>
<div id="rightCt" class="easyui-tabs">
<!--主体内容tab1-->
	<div id="tab1" title="加入任务">
	任务大厅是为项目匹配、任务承接的核心区域
	项目匹配：项目发布者快速选择其他非竞争性项目，合并为完整任务
	任务承接：团队快速选择非竞争性任务，承接并投放
<table style="width:793px">
<tr valign="top"><td align="center">
		<div id="myprj">
		<input type="hidden" value="{$_SESSION['UserInfo']['paySecret']}" id="secpay"	/>	
		<php>$rtArraympj = getPrjList('beginExec','Normal'); $prjList = $rtArraympj['a'];$pagempj =$rtArraympj['b'];</php>
				<label style="font-size:12px">选择项目<select  id="selprjid1" onChange="showprj(this.value)">
				  <option value="项目ID" selected>项目ID</option>				  
				  <volist name="prjList" id="vo">
				  <option value="{$vo.id_gezi_prj}">{$vo.id_gezi_prj}</option>	
				 </volist>
		      </select>
			  </label>
			  <volist name="prjList" id="vo">
  				  <input type="hidden" value="{$vo.geziPerPage}" id="geziPerPage{$vo.id_gezi_prj}"	/>
				  <input type="hidden" value="{$vo.geziNum}" id="geziNum{$vo.id_gezi_prj}"	/>
				  <input type="hidden" value="{$vo.pageNum}" id="pageNum{$vo.id_gezi_prj}"	/>
				  <input type="hidden" value="{$vo.ctime}" id="ctime{$vo.id_gezi_prj}"	/>
				  <input type="hidden" value="{$vo.owner}" id="owner{$vo.id_gezi_prj}"	/>				  				  				  				  		  
				  <input type="hidden" value="{$vo.type}" id="type{$vo.id_gezi_prj}"	/>	
				  <input type="hidden" value="{$vo.id_gezi_prj}" id="id_gezi_prj{$vo.id_gezi_prj}"	/>	
			 </volist>		
		<table style="font-size:12px; width:inherit" border="1">
		<th colspan="8">选中要匹配的执行项目</th>
		<tr bgcolor="#FF9900" class="drag" ><td colspan="8">项目ID:<span id="id_gezi_prj"></span>::拖拽这里到右侧任务</td></tr>				
		<tr><td>张数</td><td>格子/每张</td><td colspan="3">格子总数</td><td>所有人</td><td>创建时间</td><td>类别</td></tr>	
		<tr><td><span id="pageNum"></span></td><td><span id="geziPerPage"></span></td><td colspan="3"><span id="geziNum"></span></td>
		<td><span id="owner"></span></td><td><span id="ctime"></span></td><td><span id="type"></span></td></tr>			
		</table>	  		
					
		</div>
</td>

<td align="center">
		
		<php>$TaskListctr = getTaskAllList();</php>
			<label style="font-size:12px">选择任务<select  id="seltaskid1" onChange="if(this.value!='任务ID')showtask('dtask',this.value)">
			  <option value="任务ID" selected>任务ID</option>				  
			  <volist name="TaskListctr" id="voo">
			  <option value="{$voo.id_gezi_task}">{$voo.id_gezi_task}</option>
			  </volist>
		  		</select>
		  </label>
		  <volist name="TaskListctr" id="vbo">
			<input type="hidden" value="{$vbo.task_ctime}" id="task_ctime{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.TpageNum}" id="TpageNum{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.percent}" id="percent{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.status}" id="status{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.task_type}" id="task_type{$vbo.id_gezi_task}"	/>			  				  				  				  		  
			  <input type="hidden" value="{$vbo.tTgezi}" id="tTgezi{$vbo.id_gezi_task}"	/>	
			  <input type="hidden" value="{$vbo.nowGezi}" id="nowGezi{$vbo.id_gezi_task}"	/>
			  <input type="hidden" value="{$vbo.nowLoc}" id="nowLoc{$vbo.id_gezi_task}"	/>			  					  				  
			  <input type="hidden" value="{$vbo.score}" id="score{$vbo.id_gezi_task}"	/>					  				  
			  <input type="hidden" value="{$vbo.id_gezi_task}" id="id_gezi_task{$vbo.id_gezi_task}"	/>
		  </volist>
		<table style="font-size:12px" 	 border="1">
		<th colspan="11">选中要匹配的任务</th>
		<tr bgcolor="#FF9900" class="drag" ><td colspan="11">任务ID:<span id="did_gezi_task"></span></td></tr>				
		<tr><td>创建时间</td><td>张数</td><td colspan="3">满格率</td><td>占位</td><td>空位</td><td>格子总数</td><td>类别</td><td>状态</td><td>分数</td></tr>
		<tr><td><span id="dtask_ctime"></span></td><td><span id="dTpageNum"></span></td><td colspan="3"><span id="dpercent"></span></td>
		<td><span id="dnowGezi"></span></td><td><span id="dnowLoc"></span></td>
		<td><span id="dtTgezi"></span></td><td><span id="dtask_type"></span></td><td><span id="dstatus"></span></td>
		<td><span id="dscore"></span></td></tr>			
		</table>
		
</td>
</tr>
<tr valign="top" align="center"><td bordercolor="#FFCC99" ><div style="border:#E0ECFF solid 1px; height:426px;" id="pdts"></div></td>

<td align="center" bordercolor="#3333FF" >
<div  id="taskpdts" style="border:#E0ECFF solid 1px;">
	<table>
	<tr  bgcolor="#FF9900"><td colspan="4">正面</td> </tr>
	<tr><td><div id="dtask1"></div></td><td><div id="dtask2"></div></td><td><div id="dtask3"></div></td><td><div id="dtask4"></div></td></tr>
	<tr><td><div id="dtask5"></div></td><td><div id="dtask6"></div></td><td><div id="dtask7"></div></td><td><div id="dtask8"></div></td></tr>
	<tr><td><div id="dtask9"></div></td><td><div id="dtask10"></div></td><td><div id="dtask11"></div></td><td><div id="dtask12"></div></td></tr>
	<tr  bgcolor="#FF9900"><td colspan="4">反面</td> </tr>
	<tr><td><div id="dtask13"></div></td><td><div id="dtask14"></div></td><td><div id="dtask15"></div></td><td><div id="dtask16"></div></td></tr>
	<tr><td><div id="dtask17"></div></td><td><div id="dtask18"></div></td><td><div id="dtask19"></div></td><td><div id="dtask20"></div></td></tr>
	<tr><td><div id="dtask21"></div></td><td><div id="dtask22"></div></td><td><div id="dtask23"></div></td><td><div id="dtask24"></div></td></tr>			
	</table>
</div>
</td></tr>

</table>


	</div>
<!--主体内容-->
<!--主体内容tab2-->
	<div id="tab2" style="text-align:center" title="承接任务" cache="false" href="__APP__/Task/showTask?status=Full&check=2">

	</div>
<!--主体内容-->

<!--主体内容tab3-->
	<div id="tab3" style="text-align:center" title="创建任务" cache="false" href="__APP__/Task/createTask">

	</div>
<!--主体内容-->

</div>
	<div id="winpop" class="easyui-window"  closed="true" closable="false" title="Pop" style="width:600px;height:550px;">
	<div id="pop" title="提交快捷项目的推广产品信息" collapsible="false"  style="padding:10px;width:635px;height:450px">
	</div>
			请点击提交产品信息按钮
	</div>
</body>
</html>